package com.financing.platform.vo;

import java.math.BigDecimal;
import java.util.Date;

import com.financing.platform.common.CsvExportable;
import com.financing.platform.util.DateUtil;
import com.financing.platform.util.StringUtil;



/**
 * 订单清单-报表VO
 * @author lisu
 *
 */
public class OrderDetailedListVO extends BaseVO implements CsvExportable{

	/**
	 * 
	 */
	private static final long serialVersionUID = -4249746264595045604L;
	
	private String orderId;
	private String orderCode;
	private String orderStatus;
	private String pName;
	private String uName;
	private String uId;
	private Date orderDate;
	private BigDecimal orderAmount;
	private BigDecimal rebateRate;
	private BigDecimal rebateAmount;
	private Date establishmentTime;
	private String uRole;
	private String pUserName;
	private Date rebateDate;
	private String oDefriendStatus;//拉黑状态，1：正常，2拉黑
	
	
	
	private String orderDateStart;
	private String orderDateEnd;
	
	public String getOrderStatus() {
		return orderStatus;
	}
	public void setOrderStatus(String orderStatus) {
		this.orderStatus = orderStatus;
	}
	public String getpName() {
		return pName;
	}
	public void setpName(String pName) {
		this.pName = pName;
	}
	public String getuName() {
		return uName;
	}
	public void setuName(String uName) {
		this.uName = uName;
	}
	public String getOrderId() {
		return orderId;
	}
	public void setOrderId(String orderId) {
		this.orderId = orderId;
	}
	public String getuId() {
		return uId;
	}
	public void setuId(String uId) {
		this.uId = uId;
	}
	public Date getOrderDate() {
		return orderDate;
	}
	public void setOrderDate(Date orderDate) {
		this.orderDate = orderDate;
	}
	public BigDecimal getOrderAmount() {
		return orderAmount;
	}
	public void setOrderAmount(BigDecimal orderAmount) {
		this.orderAmount = orderAmount;
	}
	public BigDecimal getRebateRate() {
		return rebateRate;
	}
	public void setRebateRate(BigDecimal rebateRate) {
		this.rebateRate = rebateRate;
	}
	public BigDecimal getRebateAmount() {
		return rebateAmount;
	}
	public void setRebateAmount(BigDecimal rebateAmount) {
		this.rebateAmount = rebateAmount;
	}
	public Date getEstablishmentTime() {
		return establishmentTime;
	}
	public void setEstablishmentTime(Date establishmentTime) {
		this.establishmentTime = establishmentTime;
	}
	public String getuRole() {
		return uRole;
	}
	public void setuRole(String uRole) {
		this.uRole = uRole;
	}
	public Date getRebateDate() {
		return rebateDate;
	}
	public void setRebateDate(Date rebateDate) {
		this.rebateDate = rebateDate;
	}
	public String getOrderDateStart() {
		return orderDateStart;
	}
	public void setOrderDateStart(String orderDateStart) {
		this.orderDateStart = orderDateStart;
	}
	public String getOrderDateEnd() {
		return orderDateEnd;
	}
	public void setOrderDateEnd(String orderDateEnd) {
		this.orderDateEnd = orderDateEnd;
	}
	@Override
	public String csvTitle() {
		return "ID,订单ID,状态,产品名,直销,FAID,预约时间,金额(W),佣金费率(%),佣金,产品成立时间,返佣时间,用户是否通过认证,是否拉黑,产品部（负责人）,财富管理部,财务";
	}

	@Override
	public String toCsvString() {
		StringBuilder builder = new StringBuilder();
		builder.append(getOrderId()).append(",")
		.append("'"+getOrderCode()).append(",")
		.append(checkOrderStatus(getOrderStatus())).append(",")
		.append(checkString(getpName())).append(",")
		.append(",")
		.append(getuId()).append(",")
		.append(DateUtil.getString(getOrderDate(), DateUtil.DEFAULT_DATE_FORMAT)).append(",")
		.append(checkOrderAmount(getOrderAmount())).append(",")
		.append(checkInt(getRebateRate())).append(",")
		.append(checkInt(getRebateAmount())).append(",")
		.append(DateUtil.getString(getEstablishmentTime(), DateUtil.DEFAULT_DATE_FORMAT)).append(",")
		.append(DateUtil.getString(getRebateDate(), DateUtil.DEFAULT_DATE_FORMAT)).append(",")
		.append(checkGetuRole(getuRole())).append(",")
		.append(checkDefriendStatus(getoDefriendStatus())).append(",")
		.append(checkString(getpUserName())).append(",")
		.append(",")
		.append(",");
		return builder.toString();
	}
	/**
	 * checkString
	 * @param status
	 * @return
	 */
	public  String checkString(String status){
		if(StringUtil.isNullOrEmptyStr(status)){
			return "";
		}else{
			return status.replaceAll(",", "，");
		}	
	}
	/**
	 * checkInt
	 * @param status
	 * @return
	 */
	public  String checkInt(Object i){
		if(i == null){
			return "";
		}else{
			return i.toString();
		}	
	}
	private String checkDefriendStatus(String role){
		if(StringUtil.isNullOrEmptyStr(role)){
			return "";
		}else if("1".equals(role)){
			return "否";
		}else if("2".equals(role)){
			return "是";
		}
		return "";
	}
	private String checkGetuRole(String role){
		if(StringUtil.isNullOrEmptyStr(role)){
			return "";
		}else if("1".equals(role)){
			return "否";
		}else if("99".equals(role)){
			return "否";
		}else if("98".equals(role)){
			return "否";
		}else{
			return "是";
		}	
	}
	private String checkOrderStatus(String status){
		if(StringUtil.isNullOrEmptyStr(status)){
			return "";
		}else if("110".equals(status) || "120".equals(status) || "121".equals(status)  || "122".equals(status) || "123".equals(status) || "124".equals(status) ){
			return "预约已提交";
		}else if("130".equals(status)){
			return "预约已成功";
		}else if("140".equals(status)){
			return "预约失败";
		}else if("210".equals(status)){
			return "合同已寄出";
		}else if("220".equals(status)){
			return "已签约打款";
		}else if("240".equals(status)){
			return "等待产品成立";
		}else if("250".equals(status)){
			return "产品已成立";
		}else if("310".equals(status) || "311".equals(status) || "312".equals(status) || "313".equals(status) ){
			return "对帐中";
		}else if("314".equals(status)){
			return "已对帐";
		}else if("320".equals(status)){
			return "已返佣";
		}else if("330".equals(status)){
			return "反佣已确认";
		}else if("999".equals(status)){
			return "已取消";
		}
		return "";
	}
	private String checkOrderAmount(BigDecimal orderAmount){
		if(orderAmount== null){
			return "";
		}
		return orderAmount.divide(new BigDecimal(10000),2, BigDecimal.ROUND_HALF_UP).toString();
	}
	public String getpUserName() {
		return pUserName;
	}
	public void setpUserName(String pUserName) {
		this.pUserName = pUserName;
	}
	public String getOrderCode() {
		return orderCode;
	}
	public void setOrderCode(String orderCode) {
		this.orderCode = orderCode;
	}
	public String getoDefriendStatus() {
		return oDefriendStatus;
	}
	public void setoDefriendStatus(String oDefriendStatus) {
		this.oDefriendStatus = oDefriendStatus;
	}
	
}
